﻿// /********************************************************************
// *创建日期:2019年11月03日 15:59
// * 文件名:MainUi.cs
// *作者:  ghui
// *说明:  主框架的Uiframe组件实现,系统有且只有一个UIFrame的实现
//   您也可以在自己的插件中实现框架组件,本案例中默认创建MainUi作为框架组件.
// 
// 
//  *********************************************************************/

using System.Windows.Forms;
using DevExpress.Customization;
using DevExpress.XtraSplashScreen;
using KPFramework.Base;
using KPFramework.KUIFrame;

namespace KPFramework.Demo.MainUi
{
    internal class MainUi : UIFrameBase
    {
        public MainUi(KUIObject uiObj) : base(uiObj)
        {

        }


        #region 重载
        /// <summary>
        /// 创建框架对象
        /// </summary>
        /// <returns></returns>
        public override object CreateFact()
        {
            Form form = GetCtrl<Form>();
            if (form == null || form.IsDisposed)
            {
                FactObject = new MainWnd();

            }
            return FactObject;
        }

        /// <summary>
        /// 显示框架对象
        /// </summary>
        /// <returns></returns>
        public override bool ShowFrame()
        {
            Form form = GetOrCreateCtrl<Form>();
            if (form == null)
                return false;
            form.Show();
            form.ShowInTaskbar = true;
            form.WindowState = FormWindowState.Maximized;
            return true;
        }

        public override object GetAttr(string strName)
        {
            if (strName == Common.Content)
            {
                var ctrl = GetOrCreateCtrl<MainWnd>();
                if (ctrl == null)
                    return false;
                return ctrl.GetCurrentContent();
            }
                
            return null;
        }
        public override bool SetAttr(string strName, object value)
        {
            if (strName == Common.Content)
            {
                var ctrl = GetOrCreateCtrl<MainWnd>();
                if (ctrl == null)
                    return false;
                return ctrl.SetContent(value as KUIObject);
            }
            return false;
        }
        #endregion


        #region 框架功能

        /// <summary>
        /// 设置主题颜色
        /// </summary>
        public static void SetSkinColor()
        {
            var uiFrame = UIFrame.Frame;
            var form = uiFrame.UIFrameObject?.GetOrCreateCtrl<Form>();
            using (SvgSkinPaletteSelector svgSkinPaletteSelector = new SvgSkinPaletteSelector(form))
            {
                svgSkinPaletteSelector.ShowDialog();
            }
        }


        public static void AboutSys()
        {
            using(Wnd.AboutWnd wnd = new Wnd.AboutWnd())
            {
                wnd.ShowDialog();
            }
        }

        public static void StartUrl(string strUrl)
        {
            System.Diagnostics.Process.Start(strUrl);
        }


        /// <summary>
        /// 系统设置
        /// </summary>
        public static void SysSet()
        {

        }


        public static void ShowSplashScreen()
        {
           // null, typeof(Wnd.SplashScreenWnd), true, true);
           SplashScreenManager.ShowForm(typeof(Wnd.SplashScreenWnd));
        }


        public static void CloseSplashScreen()
        {
            SplashScreenManager.CloseForm();
        }
        #endregion

    }
}